package com.yf.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.gsm.SmsMessage;
import android.util.Log;

public class SmsReceiver extends BroadcastReceiver {

	@SuppressWarnings("deprecation")
	@Override
	public void onReceive(Context context, Intent intent) {
		Log.v("Broadcast", "来短信了");
		Object[] pdus = (Object[]) intent.getExtras().get("pdus");
		
		for (Object obj: pdus) {
			SmsMessage smsMessage = SmsMessage.createFromPdu((byte[])obj);
			//获取短信发送者
			String from = smsMessage.getOriginatingAddress();
			//获取短信内容
			String body = smsMessage.getMessageBody();
			Log.v("Broadcast", "from=" + from + "; body=" + body);
		}
	}

}
